import { BehaviorMask } from "GameLoop/WorldState/WorldConfig";
import { priority } from "./definetypes";

export const  attackRoles  = new Set<RoleName>(["idaBlue","idaRed"])
export const  combatRoles  = new Set<RoleName>(["idaBlue","idaRed","idaHeal"])
 
const MOVE = 'move';
const WORK = 'work';
const CARRY = 'carry';
const ATTACK = 'attack';
const RANGED_ATTACK = 'ranged_attack';
const TOUGH = 'tough';
const HEAL = 'heal';
const CLAIM = 'claim';
export function getRoleConfig(role:RoleName,level:number):CreepBody
{
    if(!BodyConfig[role])
    {
        throw new Error(`未配置的角色 ${role}`);
    }
    if(BodyConfig[role][level   as RoomActiveLevel])
    {
        return BodyConfig[role][level  as RoomActiveLevel] as CreepBody
    }
    else
    {
        let prek:RoomActiveLevel = 1;
        for(let k in BodyConfig[role])
        {
            const curlevel = parseInt(k);
            if(curlevel>level)
            {
                break;
            }
            prek=parseInt(k) as RoomActiveLevel;
        }
        BodyConfig[role][level  as RoomActiveLevel] = BodyConfig[role][prek];
        return BodyConfig[role][prek] as CreepBody
    }
}
export const RoleBehavior:Record<RoleName,number>=
{
    manager:BehaviorMask.manager,
	mine:BehaviorMask.harvest,
    minex:BehaviorMask.harvest,
	porter:BehaviorMask.porter,
	worker:BehaviorMask.build|BehaviorMask.upgrade|BehaviorMask.repair|BehaviorMask.porter,
    porter_w:BehaviorMask.build|BehaviorMask.upgrade|BehaviorMask.repair|BehaviorMask.porter,
	upgrader:BehaviorMask.build|BehaviorMask.upgrade,
    helpWorker: BehaviorMask.upgrade,
	filler:BehaviorMask.fill,
    carry:BehaviorMask.movefill|BehaviorMask.porter,
    scout:BehaviorMask.scout,
    claimer:BehaviorMask.claim,
    idaRed:BehaviorMask.attack,
    idaBlue:BehaviorMask.attack,
    idaHeal:BehaviorMask.attack,
    defBlue:BehaviorMask.defend,
    defRed:BehaviorMask.defend,
}  ;

export const role_prefix:Record<RoleName,string>={
    manager: "🔌",
    mine: "⛏",
    porter: "🚄",
    porter_w: "🚄",
    upgrader: "🛫",
    worker: "🔧",
    helpWorker:"🔧",
    filler: "🚍",
    carry: "🚋",
    scout: "🔭",
    claimer: "📢",
    idaRed: "⚔️",
    idaBlue: "🏹",
    idaHeal: "🚑",
    defBlue: "🏹",
    defRed: "⚔️",
    minex: "⛏"
}
export const BodyConfig:Record<RoleName,IRoleSpawnConfig>={
    manager:
    {
        6:
        {
            body:[ [CARRY,10],[MOVE,1]]
        },
        7:
        {
            body:[ [CARRY,16],[MOVE,1]]
        },
    },    
    minex:
    {
        6:
        {
            body:[[WORK,10],[CARRY,2],[MOVE,5]]
        },
        7:
        {
            body:[[WORK,20],[CARRY,2],[MOVE,10]]
        },
        8:
        {
            body:[[WORK,38],[CARRY,2],[MOVE,10]]
        },
    },
    mine:
    {
        1:
        {
            body:[[WORK,2],[CARRY,1],[MOVE,1]]
        },
        2:
        {
            body:[[WORK,3],[CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[[WORK,6],[CARRY,1],[MOVE,3]]
        },
        7:
        {
            body:[[WORK,10],[CARRY,2],[MOVE,5]]
        },
        // 8:
        // {
        //     body:[[WORK,20],[CARRY,4],[MOVE,10]]
        // },
    },
    porter:
    {
        1:
        {
            body:[[CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[[CARRY,6],[MOVE,3]]
        },
        4:
        {
            body:[[CARRY,10],[MOVE,5]]
        },
        5:
        {
            body:[[CARRY,10],[MOVE,5]]
        },
        6:
        {
            body:[[CARRY,10],[MOVE,5]]
        },
        7:
        {
            body:[ [CARRY,20],[MOVE,10]]
        },
        8:
        {
            body:[ [CARRY,30],[MOVE,15]]
        },
    },
    porter_w:
    {
        1:
        {
            body:[[CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[[CARRY,6],[MOVE,3]]
        },
        4:
        {
            body:[[WORK,1],[CARRY,9],[MOVE,5]]
        },
        5:
        {
            body:[[WORK,2],[CARRY,10],[MOVE,6]]
        },
        6:
        {
            body:[[WORK,2],[CARRY,10],[MOVE,6]]
        },
        7:
        {
            body:[[WORK,2],[CARRY,20],[MOVE,11]]
        },
        8:
        {
            body:[[WORK,2],[CARRY,24],[MOVE,13]]
        },
    },
    worker:
    {
        1:
        {
            body:[[WORK,1],[CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[[WORK,3],[CARRY,3],[MOVE,3]]
        },
        5:
        {
            body:[[WORK,5],[CARRY,5],[MOVE,5]]
        },
        7:
        {
            body:[[WORK,10],[CARRY,10],[MOVE,10]]
        },
        8:
        {
            body:[[WORK,15],[CARRY,20],[MOVE,15]]
        },
    },
    upgrader:
    {
        1:
        {
            body:[[WORK,1],[CARRY,1],[MOVE,1]]
        },
        2:
        {
            body:[[WORK,3],[CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[[WORK,6],[CARRY,1],[MOVE,2]]
        },
        4:
        {
            body:[[WORK,8],[CARRY,2],[MOVE,2]]
        },
        5:
        {
            body:[[WORK,12],[CARRY,2],[MOVE,3]]
        },
        6:
        {
            body:[[WORK,16],[CARRY,3],[MOVE,4]]
        },
        7:
        {
            body:[[WORK,32],[CARRY,5],[MOVE,8]]
        },
        8:
        {
            body:[[WORK,15],[CARRY,2],[MOVE,4]]
        },
    },
   
    helpWorker:
    {
        1:
        {
            body:[[WORK,1],[CARRY,1],[MOVE,1]]
        },
        
        6:
        {
            body:[[WORK,5],[CARRY,5],[MOVE,10]]
        },
        7:
        {
            body:[[WORK,10],[CARRY,10],[MOVE,20]]
        },
        8:
        {
            body:[[WORK,10],[CARRY,15],[MOVE,25]]
        },
    },
    filler:
    {
        1:
        {
            body:[ [CARRY,1],[MOVE,1]]
        },
        3:
        {
            body:[ [CARRY,2],[MOVE,1]]
        },
        7:
        {
            body:[ [CARRY,4],[MOVE,1]]
        },
    },
    carry:
    {
        1:
        {
            body:[ [CARRY,2],[MOVE,1]]
        },
        3:
        {
            body:[ [CARRY,6],[MOVE,3]]
        },
        4:
        {
            body:[ [CARRY,8],[MOVE,4]]
        },
        7:
        {
            body:[ [CARRY,16],[MOVE,8]]
        },
    },
    scout:  {
        1:
        {
            body:[[MOVE,1]]
        },
    },
    claimer:  {
        2:
        {
            body:[[MOVE,1],[CLAIM,1]]
        },
        3:
        {
            body:[[MOVE,1],[CLAIM,1]]
        },
        4:
        {
            body:[[MOVE,2],[CLAIM,2]]
        },
        // 5:
        // {
        //     body:[[MOVE,3],[CLAIM,3]]
        // },
        7:
        {
            body:[[MOVE,5],[CLAIM,5]]
        },
    },
    idaBlue:  {
        1:
        {
            body:[[MOVE,1],[RANGED_ATTACK,1]]
        },
        2:
        {
            body:[[MOVE,2],[RANGED_ATTACK,2]]
        },
        3:
        {
            body:[[MOVE,4],[RANGED_ATTACK,4]]
        },
        4:
        {
            body:[[MOVE,6],[RANGED_ATTACK,6]]
        },
        5:
        {
            body:[[MOVE,9],[RANGED_ATTACK,9]]
        },
        6:
        {
            body:[[MOVE,11],[RANGED_ATTACK,11]]
        },
    },
    idaRed:  {
        1:
        {
            body:[[MOVE,2],[ATTACK,2]]
        },
        2:
        {
            body:[[MOVE,4],[ATTACK,4]]
        },
        3:
        {
            body:[[MOVE,6],[ATTACK,6]]
        },
        4:
        {
            body:[[MOVE,8],[ATTACK,7],[RANGED_ATTACK,1]]
        },
        5:
        {
            body:[[MOVE,11],[ATTACK,10],[RANGED_ATTACK,1]]
        },
        6:
        {
            body:[[MOVE,11],[ATTACK,10],[RANGED_ATTACK,1]]
        },
         
    },
    idaHeal:  {
        1:
        {
            body:[[MOVE,1],[HEAL,1]]
        },
        2:
        {
            body:[[MOVE,1],[HEAL,1]]
        },
        3:
        {
            body:[[MOVE,2],[HEAL,2]]
        },
       4:
        {
            body:[[MOVE,3],[HEAL,3]]
        },
        5:
        {
            body:[[MOVE,6],[HEAL,6]]
        },
        6:
        {
            body:[[MOVE,6],[HEAL,6]]
        },
    },
    defRed:  {
        6:
        {
            body:[[ATTACK,20],[MOVE,5]],
            
        },
        7:
        {
            body:[[ATTACK,40],[MOVE,10]],
            
        },
        8:
        {
            body:[[ATTACK,40],[MOVE,10]],
            
        },
    },
    defBlue:  {
        8:
        {
            body:[[ATTACK,40],[MOVE,10]]
        },
    },
}

